package com.my;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Map;

/**
 * Created by YJH on 2017/6/23 10:35.
 */
public class LoginServlet implements Servlet {

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        System.out.println("请求来了...");
//
//        String user = servletRequest.getParameter("user");
//        String password = servletRequest.getParameter("password");
//
//        System.out.println(user + "，" + password);
//
//        String[] interestings = servletRequest.getParameterValues("interesting");
//        for (String s : interestings) {
//            System.out.println(s);
//        }
//
//        System.out.println("\n");
//        Enumeration<String> names = servletRequest.getParameterNames();
//        while (names.hasMoreElements()) {
//            String name = names.nextElement();
//            String val = servletRequest.getParameter(name);
//            System.out.println(name + "，" + val);
//        }
//
//        System.out.println("\n");
//        Map<String, String[]> map = servletRequest.getParameterMap();
//        for (Map.Entry<String, String[]> entry : map.entrySet()) {
//            System.out.println(entry.getKey() + "，" + Arrays.asList(entry.getValue()));
//        }
//
//        System.out.println("\n");
//        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
//        System.out.println(httpServletRequest.getRequestURI()); //获取请求地址
//        System.out.println(httpServletRequest.getMethod());     //获取请求方式
//
//        System.out.println("\n");
//        System.out.println(httpServletRequest.getQueryString());    //获取get请求后面追加的串
//
//        System.out.println("\n");
//        System.out.println(httpServletRequest.getServletPath());    //获取请求地址前段

        servletResponse.setContentType("application/msword");
        PrintWriter writer = servletResponse.getWriter();
        writer.println("Hello~");
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
